#include <stdint.h>
#include <stdio.h>
#include "aoaoutil.h"

void log_array(uint8_t *data, uint16_t len)
{
    printf("[");
    for (uint16_t i = 0; i < len; i++)
    {
        printf("0x%02X", data[i]);
        if (i != len - 1)
        {
            printf(", ");
        }
    }
    printf("]");
}

void aut16(void)
{
    uint8_t array[sizeof(uint16_t)] = {0};
    uint16_t tovalue = 0x0000;
    uint16_t fromvalue = 0x0123;

    printf("u16 fromvalue: 0x%X\n", fromvalue);
    aut_afromu16(array, fromvalue);
    printf("aut_afromu16 ");
    log_array(array, sizeof(uint16_t));
    printf("\n");
    printf("aut_atou16: 0x%X\n", aut_atou16(array));

    printf("\n");

    printf("u16 fromvalue: 0x%X\n", fromvalue);
    aut_afromu16_be(array, fromvalue);
    printf("aut_afromu16_be ");
    log_array(array, sizeof(uint16_t));
    printf("\n");
    printf("aut_atou16_be: 0x%X\n", aut_atou16_be(array));

    printf("\n");

    printf("u16 fromvalue: 0x%X\n", fromvalue);
    aut_afromu16_le(array, fromvalue);
    printf("aut_afromu16_le ");
    log_array(array, sizeof(uint16_t));
    printf("\n");
    printf("aut_atou16_le: 0x%X\n", aut_atou16_le(array));
}

void aut32(void)
{
    uint8_t array[sizeof(uint32_t)] = {0};
    uint32_t tovalue = 0x0000;
    uint32_t fromvalue = 0x01234567;

    printf("u32 fromvalue: 0x%X\n", fromvalue);
    aut_afromu32(array, fromvalue);
    printf("aut_afromu32 ");
    log_array(array, sizeof(uint32_t));
    printf("\n");
    printf("aut_atou32: 0x%X\n", aut_atou32(array));

    printf("\n");

    printf("u32 fromvalue: 0x%X\n", fromvalue);
    aut_afromu32_be(array, fromvalue);
    printf("aut_afromu32_be ");
    log_array(array, sizeof(uint32_t));
    printf("\n");
    printf("aut_atou32_be: 0x%X\n", aut_atou32_be(array));

    printf("\n");

    printf("u32 fromvalue: 0x%X\n", fromvalue);
    aut_afromu32_le(array, fromvalue);
    printf("aut_afromu32_le ");
    log_array(array, sizeof(uint32_t));
    printf("\n");
    printf("aut_atou32_le: 0x%X\n", aut_atou32_le(array));
    printf("\n");
}

void aut64(void)
{
    uint8_t array[sizeof(uint64_t)] = {0};
    uint64_t tovalue = 0x0000;
    uint64_t fromvalue = 0x0123456789ABCDEF;

    printf("u64 fromvalue: 0x%lX\n", fromvalue);
    aut_afromu64(array, fromvalue);
    printf("aut_afromu64 ");
    log_array(array, sizeof(uint64_t));
    printf("\n");
    printf("aut_atou64: 0x%lX\n", aut_atou64(array));

    printf("\n");

    printf("u64 fromvalue: 0x%lX\n", fromvalue);
    aut_afromu64_be(array, fromvalue);
    printf("aut_afromu64_be ");
    log_array(array, sizeof(uint64_t));
    printf("\n");
    printf("aut_atou64_be: 0x%lX\n", aut_atou64_be(array));

    printf("\n");

    printf("u64 fromvalue: 0x%lX\n", fromvalue);
    aut_afromu64_le(array, fromvalue);
    printf("aut_afromu64_le ");
    log_array(array, sizeof(uint64_t));
    printf("\n");
    printf("aut_atou64_le: 0x%lX\n", aut_atou64_le(array));
    printf("\n");
}

int main(int argc, char const *argv[])
{
    // aut16();
    aut32();
    // aut64();

    return 0;
}
